package com.bite.mybatis.mapper;

import com.bite.mybatis.model.UserInfo;
import org.apache.catalina.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserInfoMapper {
    @Results(id = "basemap",value = {
            @Result(column = "delete_flag",property = "deleteFlag"),
            @Result(column = "create_time",property = "createTime"),
            @Result(column = "update_time",property = "updateTime")

    })
    @Select("select * from user_info")
    List<UserInfo> selectAll();

    @ResultMap(value = "basemap")
    @Select("select * from user_info where id = #{id}")
    List<UserInfo> selectById(Integer id);

    //@ResultMap(value = "basemap")
    @Select("SELECT * from user_info where username = #{username} and password = #{password}")
    List<UserInfo> selectByUsernameAndPassward(String username,String password);

    //SQL注入
    @Select("SELECT * from user_info where username ='${username}' and password = '${password}'")
    List<UserInfo> selectByUsernameAndPassward3(String username,String password);

    @Select("SELECT * from user_info where username = #{userInfo.username} and password = #{userInfo.password}")
    List<UserInfo> selectByUsernameAndPassward2(@Param("userInfo") UserInfo userInfo);

    @ResultMap(value = "basemap")
    @Options(useGeneratedKeys = true,keyProperty = "id")
    @Insert("insert into user_info (username,password,age) VALUES (#{username},#{password},#{age})")
    Integer insertUser(UserInfo userInfo);


    @Update("update user_info set password = #{userinfo.password} where id = #{setId}")
    Integer updateUser(@Param("userinfo") UserInfo userInfo,@Param("setId") Integer id);

    @Delete("delete from user_info where id = #{id}")
    Integer deletUser(Integer id);
}





